package com.pactera.utils;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;

public class ExceptionUtils {

    private static final Logger log = LoggerFactory.getLogger(ExceptionUtils.class);

    private ExceptionUtils() {
    }

    /**
     * 获取错误详情
     *
     * @author: EC_liqingdian
     */
    public static String getException(Exception e) {
        StringWriter stringWriter = null;
        PrintWriter writer = null;
        try {
            stringWriter = new StringWriter();
            writer = new PrintWriter(stringWriter);
            e.printStackTrace(writer);
        } finally {
            if (writer != null) {
                writer.close();
            }
            if (stringWriter != null) {
                try {
                    stringWriter.close();
                } catch (IOException e1) {
                    log.error(e1.getMessage(), e1);
                }
            }
        }
        return stringWriter.toString();
    }

}
